package com.easy.dn.ui.main.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.easy.dn.bean.UserExperienceBean;
import com.easy.dn.utils.DnUtils;
import com.google.android.flexbox.FlexboxLayout;

import java.util.List;

import dn.easy.com.easyto.R;


/**
 * 工作经验 adapter
 * <p>
 * Created by 丁宁
 * on 2017/8/9.
 */

public class WorkExpsAdapter extends BaseQuickAdapter<UserExperienceBean, BaseViewHolder> {

    public WorkExpsAdapter(@LayoutRes int layoutResId, @Nullable List<UserExperienceBean> childData) {
        super(layoutResId, childData);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserExperienceBean item) {
        //公司名称
        if (item.getCompanyName()==null||"".equals(item.getCompanyName())){
            helper.setVisible(R.id.tv_exp_company,false);
        }else {
            helper.setText(R.id.tv_exp_company, item.getCompanyName());
        }
        //行业
        if (item.getTradeStr()==null||"".equals(item.getTradeStr())){
            helper.setVisible(R.id.tv_exp_trade,false);
        }else {
            helper.setText(R.id.tv_exp_trade, item.getTradeStr());
        }

        //职位
        if (item.getJobTypeStr()==null||"".equals(item.getJobTypeStr())){
            helper.setVisible(R.id.tv_exp_job,false);
        }else {
            helper.setText(R.id.tv_exp_job, item.getJobTypeStr());
        }
        //工作内容
        if (item.getJobContent()==null||"".equals(item.getJobContent())){
            helper.setVisible(R.id.tv_exp_content,false);
        }else {
            helper.setText(R.id.tv_exp_content, item.getJobContent());
        }

        //公司规模
        String underMenNum = getComSize(item.getUnderMenNum() + "");
        String companySize = getComSize(item.getCompanySize() + "");
        if (underMenNum.equals("")) {
            helper.setVisible(R.id.tv_company_size, false);
        } else {
            helper.setText(R.id.tv_company_size, mContext.getResources().getString(R.string.subordinate) +  underMenNum);
        }

         if (companySize.equals("")) {
            helper.setVisible(R.id.tv_company_count, false);
        } else {
            helper.setText(R.id.tv_company_count, mContext.getResources().getString(R.string.company_size) +companySize);

        }
        //行业词组
        String exp = "";
        FlexboxLayout flexboxLayout = helper.getView(R.id.fl_trade_label);
        if (DnUtils.getLocale()) {
            exp = item.getWordTextZH();
        } else {
            exp = item.getWordTextEN();
        }
        flexboxLayout.removeAllViews();
        if (exp != null && !"".equals(exp)) {
          String[]  expArrayWord = exp.split(",");
            for (int i = 0; i < expArrayWord.length; i++) {
                TextView textView = new TextView(mContext);
                textView.setText(expArrayWord[i]);
                textView.setGravity(Gravity.CENTER);
                textView.setTextSize(13);
                textView.setBackgroundResource(R.drawable.resume_detail_label_bg);
                flexboxLayout.addView(textView);
                ViewGroup.LayoutParams params = textView.getLayoutParams();
                if (params instanceof FlexboxLayout.LayoutParams) {
                    FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) params;
                    layoutParams.setMargins(10, 10, 0, 0);
                    textView.setLayoutParams(layoutParams);
                }
            }
        }
    }

    private String getComSize(String com) {
        String str = "";
        if ("1".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale1);
        } else if ("2".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale2);
        } else if ("3".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale3);
        } else if ("4".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale4);
        } else if ("5".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale5);
        } else if ("6".equals(com)) {
            str = mContext.getResources().getString(R.string.resume_scale6);
        } else {
            str = "";
        }
        return str;
    }
}

